import { useEffect, useRef } from "react"

const useDebounce=(fn,delay)=>{
    const timer=useRef(null)
    useEffect(()=>{
        clearTimeout(timer.current)
    },[])
    return (...arg)=>{
        clearTimeout(timer.current)
        timer.current=setTimeout(()=>{
            fn(...arg)
        },delay)
    }
}
export default useDebounce